﻿using WRJClient.Common;
using NLog;
using NLog.Config;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Interop;

namespace WRJClient.Utils
{
    public class Logger
    {
        private NLog.Logger _logger = null;

        public Logger(string tag)
        {
            if (!string.IsNullOrEmpty(tag))
            {
                _logger = LogManager.GetLogger(tag);
            }
            else
            {
                _logger = LogManager.GetCurrentClassLogger();
            }
        }
        public void Trace(string msg, params object[] args)
        {
            _logger.Trace(msg, args);
        }
        public void Debug(string msg, params object[] args)
        {
            _logger.Debug(msg, args);
        }
        public void Info(string msg, params object[] args)
        {
            _logger.Info(msg, args);
        }
        public void Warn(string msg, params object[] args)
        {
            _logger.Warn(msg, args);
        }
        public void Error(string msg, params object[] args)
        {
            _logger.Error(msg, args);

            string log = string.Format(msg, args);
            
            ////弹出对话框，调试用。
            //MessageBox.Show(log);

            //UI应用显示
            MessageManager.Instance.Error(log);
        }
        public void Fatal(string msg, params object[] args)
        {
            _logger.Fatal(msg, args);

            string log = string.Format(msg, args);

            //弹出对话框，调试用。
            MessageBox.Show(log);

            //UI应用显示
            MessageManager.Instance.Error(log);
        }
    }
}
